package com.greystripe.sdk;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.webkit.JavascriptInterface;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

final class m
{
  private m(c paramc)
  {
  }

  private q a(String paramString)
  {
    q localq = new q(this.a, (byte)0);
    if (!paramString.matches(".*:\\{.*\\}"))
    {
      bd.b("no mathcey!", new Object[0]);
      return localq;
    }
    String[] arrayOfString1 = paramString.substring(1 + paramString.indexOf("{"), paramString.indexOf("}")).split("\\|");
    int i = arrayOfString1.length;
    for (int j = 0; j < i; j++)
    {
      String[] arrayOfString2 = arrayOfString1[j].trim().split(":");
      String str1 = arrayOfString2[0];
      if (arrayOfString2.length > 2)
      {
        String str2 = "";
        for (int k = 1; k < -1 + arrayOfString2.length; k++)
          str2 = str2 + arrayOfString2[k] + ":";
        arrayOfString2[1] = (str2 + arrayOfString2[(-1 + arrayOfString2.length)]);
      }
      if (arrayOfString2.length >= 2)
        localq.put(str1, arrayOfString2[1].trim());
    }
    return localq;
  }

  private void a(Intent paramIntent, String paramString)
  {
    if (paramIntent == null)
    {
      this.a.c();
      return;
    }
    try
    {
      c.o(this.a).startActivity(paramIntent);
      return;
    }
    catch (Exception localException)
    {
      bd.b("Greystripe", new Object[] { paramString });
      localException.printStackTrace();
      this.a.c();
    }
  }

  private Intent b(String paramString)
  {
    Intent localIntent = new Intent("android.intent.action.INSERT");
    q localq = a(paramString);
    if (localq.size() == 0)
      return null;
    StringBuilder localStringBuilder = new StringBuilder().append(localq.a("firstName"));
    if (localq.containsKey("lastName"));
    String str2;
    String str3;
    String str4;
    String str5;
    String str6;
    for (String str1 = " " + localq.a("lastName"); ; str1 = "")
    {
      str2 = str1;
      str3 = localq.a("phone");
      str4 = localq.a("email");
      str5 = localq.a("company");
      str6 = "";
      String[] arrayOfString = { "street", "city", "state", "zip", "country" };
      for (int i = 0; i < arrayOfString.length; i++)
      {
        String str9 = localq.a(arrayOfString[i]);
        if (str9.length() > 0)
          str6 = str6 + str9 + ", ";
      }
    }
    if (str6.endsWith(", "))
      str6 = str6.substring(0, str6.length() - ", ".length());
    String str7 = localq.a("fax");
    String str8 = localq.a("url");
    localIntent.setType("vnd.android.cursor.dir/raw_contact");
    localIntent.putExtra("name", str2);
    localIntent.putExtra("email", str4);
    localIntent.putExtra("phone", str3);
    localIntent.putExtra("company", str5);
    localIntent.putExtra("postal", str6);
    localIntent.putExtra("secondary_phone", str7);
    localIntent.putExtra("secondary_phone_type", 4);
    localIntent.putExtra("notes", str8);
    localIntent.addFlags(268435456);
    return localIntent;
  }

  private Intent c(String paramString)
  {
    Intent localIntent = new Intent("android.intent.action.EDIT");
    q localq = a(paramString);
    if (localq.size() == 0)
      return null;
    String str1 = localq.a("title");
    String str2 = localq.a("location");
    String str3 = localq.a("notes");
    String str4 = localq.a("url");
    TimeZone localTimeZone;
    if (localq.containsKey("timeZone"))
      localTimeZone = TimeZone.getTimeZone(localq.a("timeZone"));
    while (true)
    {
      SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
      localSimpleDateFormat.setTimeZone(localTimeZone);
      String str5 = localq.a("startDate");
      Calendar localCalendar1 = Calendar.getInstance();
      try
      {
        localCalendar1.setTime(localSimpleDateFormat.parse(str5));
        str6 = localq.a("endDate");
        localCalendar2 = Calendar.getInstance();
      }
      catch (ParseException localParseException1)
      {
        try
        {
          Calendar localCalendar2;
          localCalendar2.setTime(localSimpleDateFormat.parse(str6));
          if ((localq.a("allDay").startsWith("t")) || (localq.a("allDay").startsWith("y")))
          {
            bool = true;
            localIntent.setType("vnd.android.cursor.item/event");
            localIntent.addFlags(268435456);
            localIntent.putExtra("beginTime", localCalendar1.getTimeInMillis());
            localIntent.putExtra("title", str1);
            localIntent.putExtra("description", str4 + "\n" + str3);
            localIntent.putExtra("eventLocation", str2);
            localIntent.putExtra("allDay", bool);
            if (!bool)
              localIntent.putExtra("endTime", localCalendar2.getTimeInMillis());
            return localIntent;
            localTimeZone = TimeZone.getDefault();
            continue;
            localParseException1 = localParseException1;
            bd.e("Cannot parse startDate string: " + str5, new Object[0]);
          }
        }
        catch (ParseException localParseException2)
        {
          while (true)
          {
            String str6;
            bd.e("Cannot parse endDate string: " + str6, new Object[0]);
            continue;
            boolean bool = false;
          }
        }
      }
    }
  }

  @JavascriptInterface
  public final void onAdExpired()
  {
    if ((c.f(this.a)) || (c.p(this.a)))
      return;
    bd.b("onAdExpired", new Object[0]);
    c.y(this.a);
    c.z(this.a);
    c.a(this.a, GSAdErrorCode.AD_EXPIRED);
  }

  @JavascriptInterface
  public final void onAdReady()
  {
    if ((c.f(this.a)) || (c.p(this.a)));
    do
    {
      do
      {
        return;
        bd.b("onAdReady", new Object[0]);
        c.c(this.a);
        c.q(this.a);
        c.r(this.a);
        if (c.g(this.a))
        {
          c.h(this.a);
          return;
        }
      }
      while (!c.s(this.a));
      c.h(this.a);
    }
    while (!c.j(this.a));
    c.k(this.a);
  }

  @JavascriptInterface
  public final void onBlankThirdPartyAd()
  {
    c.A(this.a);
    bm.a(new n(this));
    c.a(this.a).a();
    c.e(this.a);
    this.a.a(GSAdErrorCode.NO_AD);
  }

  @JavascriptInterface
  public final void onClickthrough(String paramString)
  {
    if (c.w(this.a))
    {
      bd.b("mraid ad was expanded. exec'ing mraid.close", new Object[0]);
      c.a(this.a).b("mraid.close();");
    }
    c.t(this.a);
    c.x(this.a);
    bd.b("Clicking through: " + paramString, new Object[0]);
    if (paramString.startsWith("sms:"))
    {
      Intent localIntent1 = new Intent("android.intent.action.VIEW");
      String[] arrayOfString = paramString.split("\\?body=");
      String str1 = "";
      String str2 = "";
      if ((arrayOfString != null) && (arrayOfString.length > 0))
      {
        str1 = arrayOfString[0].substring(1 + paramString.indexOf(":"));
        if (arrayOfString.length > 1)
          str2 = arrayOfString[1];
      }
      localIntent1.setData(Uri.parse("sms:" + str1));
      localIntent1.putExtra("sms_body", str2);
      localIntent1.addFlags(268435456);
      a(localIntent1, "Failed to send SMS " + paramString);
      return;
    }
    if (paramString.startsWith("contact:"))
    {
      a(b(paramString), "Failed to save contact " + paramString);
      return;
    }
    if (paramString.startsWith("calendar:"))
    {
      a(c(paramString), "Failed to save calendar event " + paramString);
      return;
    }
    try
    {
      Intent localIntent2 = new Intent("android.intent.action.VIEW", Uri.parse(paramString));
      localIntent2.addFlags(268435456);
      c.o(this.a).startActivity(localIntent2);
      return;
    }
    catch (Exception localException)
    {
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = ("Failed to clickthrough to destination " + paramString);
      bd.b("Greystripe", arrayOfObject);
      localException.printStackTrace();
      this.a.c();
    }
  }

  @JavascriptInterface
  public final void onDismissal()
  {
    c.t(this.a);
    c.u(this.a);
    c.v(this.a);
  }

  @JavascriptInterface
  public final void saveImage(String paramString)
  {
    new o(this, paramString).start();
  }

  @JavascriptInterface
  public final void setAdId(int paramInt)
  {
    bd.b("setting adid: " + paramInt, new Object[0]);
    c.a(this.a, paramInt);
  }

  @JavascriptInterface
  public final void setAdServerUrl(String paramString)
  {
    bj.b(paramString);
  }

  @JavascriptInterface
  public final void useCamera()
  {
    this.a.b = true;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.greystripe.sdk.m
 * JD-Core Version:    0.6.2
 */